var t = getApp();

Page({
    data: {
        language: "",
        datas: [],
        isLoadMore: !1,
        total_page: 0,
        page: 1
    },
    onLoad: function(t) {
        this.getData();
    },
    onReady: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多了");
    },
    onShareAppMessage: function() {},
    getData: function() {
        var a = this, o = this, e = t.getNetAddresss("plugin.micro.frontend.controllers.MicroShop.get-goods.index");
        t._getNetWork({
            url: e,
            success: function(t) {
                var e = t.data;
                1 == e.result && (a.data.isLoadMore = !0, a.data.total_page = e.data.list.last_page, 
                a.data.total_page || (a.data.total_page = 0), o.setData({
                    datas: e.data.list.data
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getMoreData: function() {
        var a = this, o = "";
        this.data.isLoadMore = !1, this.data.page >= this.data.total_page || (this.data.page = this.data.page + 1, 
        o = t.getNetAddresss("plugin.micro.frontend.controllers.MicroShop.get-goods.index"), 
        t._postNetWork({
            url: o,
            data: {
                page: this.data.page
            },
            success: function(t) {
                var o = t.data;
                1 == o.result ? (a.data.isLoadMore = !0, a.setData({
                    datas: a.data.datas.concat(o.data.list.data)
                })) : (a.data.page = a.data.page - 1, a.isLoadMore = !1, wx.showToast({
                    icon: "none",
                    title: o.msg,
                    duration: 1500
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        }));
    },
    delteteItem: function(a) {
        var o = a.currentTarget.dataset.item, e = a.currentTarget.dataset.index, n = this, s = t.getNetAddresss("plugin.micro.frontend.controllers.MicroShop.del-goods.index");
        s += "&id=" + o.id, wx.showModal({
            title: "提示",
            content: "是否删除该商品？",
            success: function(a) {
                a.confirm ? t._getNetWork({
                    url: s,
                    success: function(t) {
                        var a = t.data;
                        if (1 == a.result) {
                            var o = n.data.datas;
                            o.splice(e, 1), n.setData({
                                datas: o
                            }), wx.showToast({
                                icon: "none",
                                title: "操作成功",
                                duration: 1500
                            });
                        } else wx.showToast({
                            icon: "none",
                            title: a.msg,
                            duration: 1500
                        });
                    },
                    fail: function(t) {
                        console.log(t);
                    }
                }) : a.cancel && console.log("用户点击取消");
            }
        });
    },
    toItem: function(t) {
        var a = t.currentTarget.dataset.goods;
        wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + a.id
        });
    }
});